package study.thread;


public class ThreadRuning extends Thread {

    public ThreadRuning(String name) {
        //重写构造，可以对线程添加名字
        super(name);
    }


    @Override
    public void run() {
        //noinspection InfiniteLoopStatement
        while (true) {
            System.out.println("good time");
            //在run方法里，this代表当前线程
            this.setName("1234");
            System.out.println(this);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
                this.interrupt();
            }
            System.out.println(State.BLOCKED.name);
        }
    }

    public enum State {
        /**
         * NEW
         */
        NEW("新的", 1),
        /**
         * RUNNABLE
         */
        RUNNABLE("新的", 1),
        /**
         * BLOCKED
         */
        BLOCKED("新的", 1),
        /**
         * WAITING
         */
        WAITING("新的", 1),
        /**
         * TIMED_WAITING
         */
        TIMED_WAITING("新的", 1),
        /**
         * TERMINATED
         */
        TERMINATED("新的", 1);

        private String name;
        private int index;

        // 构造方法

        /**
         *
         * @param name
         * @param index
         */
        private State(String name, int index) {
            this.name = name;
            this.index = index;
        }

        public static void main(String[] args) {
            ThreadRuning threadRuning = new ThreadRuning("1111");
            threadRuning.start();
        }
    }
}
